import {request} from './request.js'

export function toPublish(content,title,token,choice){
	let state2='草稿'
	if(choice==1)
		state2='已发布'
	return request({
		url:'/my/article/add',
		method: 'post',
		data:{
			content:content,
			title:title,
			state:state2,
			},
		transformRequest: [function(data) {
		                let ret = ''
		                for(let it in data) {
		                    ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
		                }
		                return ret
		            }],
		headers: {
		        'Content-Type': 'application/x-www-form-urlencoded',
				'Authorization': token
		}
	})
}

export function toCorrect(content,title,token,choice,id){
	let state2='草稿'
	if(choice==1)
		state2='已发布'
	return request({
		url:'/my/article/correct/'+id,
		method: 'post',
		data:{
			title:title,
			content:content,
			state:state2,
			},
		transformRequest: [function(data) {
		                let ret = ''
		                for(let it in data) {
		                    ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
		                }
		                return ret
		            }],
		headers: {
		        'Content-Type': 'application/x-www-form-urlencoded',
				'Authorization': token
		}
	})
}

export function Delete(id){
	return request({
		url:'/api/delete',
		params:{
			Id:id
		}
	})
}
// export function toDraft(content,token){
// 	return request({
// 		url:'/my/article/add',
// 		method:'post',
// 		data:{
// 			content:content
// 		},
// 		header:{
// 			'Content-Type': 'application/x-www-form-urlencoded',
// 			'Authorization': token
// 		}
		
// 	})
// }